{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "dates = pd.date_range('20130101',periods=6)\n",
    "df = pd.DataFrame(np.arange(24).reshape((6,4)),index=dates,columns=['A','B','C','D'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2013-01-01     0\n",
      "2013-01-02     4\n",
      "2013-01-03     8\n",
      "2013-01-04    12\n",
      "2013-01-05    16\n",
      "2013-01-06    20\n",
      "Freq: D, Name: A, dtype: int32 2013-01-01     0\n",
      "2013-01-02     4\n",
      "2013-01-03     8\n",
      "2013-01-04    12\n",
      "2013-01-05    16\n",
      "2013-01-06    20\n",
      "Freq: D, Name: A, dtype: int32\n",
      "             A   B   C   D\n",
      "2013-01-01   0   1   2   3\n",
      "2013-01-02   4   5   6   7\n",
      "2013-01-03   8   9  10  11\n",
      "2013-01-04  12  13  14  15\n",
      "2013-01-05  16  17  18  19\n",
      "2013-01-06  20  21  22  23\n",
      "            A  B   C   D\n",
      "2013-01-01  0  1   2   3\n",
      "2013-01-02  4  5   6   7\n",
      "2013-01-03  8  9  10  11             A  B   C   D\n",
      "2013-01-01  0  1   2   3\n",
      "2013-01-02  4  5   6   7\n",
      "2013-01-03  8  9  10  11\n"
     ]
    }
   ],
   "source": [
    "print(df['A'],df.A)\n",
    "print(df)\n",
    "print(df[0:3],df['20130101':'20130103'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A    0\n",
      "B    1\n",
      "C    2\n",
      "D    3\n",
      "Name: 2013-01-01 00:00:00, dtype: int32\n",
      "             A   B\n",
      "2013-01-01   0   1\n",
      "2013-01-02   4   5\n",
      "2013-01-03   8   9\n",
      "2013-01-04  12  13\n",
      "2013-01-05  16  17\n",
      "2013-01-06  20  21\n",
      "A    0\n",
      "B    1\n",
      "Name: 2013-01-01 00:00:00, dtype: int32\n"
     ]
    }
   ],
   "source": [
    "print(df.loc['20130101'])#label select从标签选\n",
    "print(df.loc[:,['A','B']])\n",
    "print(df.loc['20130101',['A','B']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A    12\n",
      "B    13\n",
      "C    14\n",
      "D    15\n",
      "Name: 2013-01-04 00:00:00, dtype: int32\n",
      "13\n",
      "             B   C\n",
      "2013-01-04  13  14\n",
      "2013-01-05  17  18\n",
      "2013-01-02     5\n",
      "2013-01-04    13\n",
      "2013-01-05    17\n",
      "Name: B, dtype: int32\n"
     ]
    }
   ],
   "source": [
    "print(df.iloc[3])#index select从index选\n",
    "print(df.iloc[3,1])\n",
    "print(df.iloc[3:5,1:3])\n",
    "print(df.iloc[[1,3,4],1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "            A   C\n",
      "2013-01-01  0   2\n",
      "2013-01-02  4   6\n",
      "2013-01-03  8  10\n",
      "             A   B   C   D\n",
      "2013-01-05  16  17  18  19\n",
      "2013-01-06  20  21  22  23\n"
     ]
    }
   ],
   "source": [
    "print(df.ix[:3,['A','C']])#mixed select混选\n",
    "print(df[df.A>12])#boolean select"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
